#pragma once
#include <iostream>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <algorithm>
#include <sstream>
#include <map>

class DataManager
{
private:
	/*Input Manager Properties*/
	std::ifstream demand;
	std::ifstream site;
	std::ifstream qos;
	std::ifstream config;

	int qosLimit, timeNum, siteNum, clientNum;
	std::vector<std::string> clientName;
	std::vector<std::string> siteName;

	std::map<std::string, int> mpSiteNameToID, mpClientNameToID;
	std::vector<std::vector<std::string>> timeStreamIDToName;

	void clearInput();

	bool hasFreopen, hasGetDemands, hasGetSiteLimits, hasGetQosGraph;


	/*Output Manager Properties*/
	int nowTime;
	int nowClient;
	int nowSite;
	std::vector<std::vector<std::vector<std::vector<int>>>> log; //[time][client][site][streamNum] = streamID
	bool hasOutputInit;

public:
	DataManager(std::string path);

	/*InputManager Method*/
	void freopen(std::string path);
	// streamNum:Time时间流种类。bandwidthDemand:[Time][Stream][Client]=bandwidthDemand
	void getDemands(int& totleTime, int& clientNum, std::vector<int>& streamNum, std::vector<std::vector<std::vector<int>>>& bandwidthDemand);
	// 按照编号顺序将边缘结点Limit放入Vector中
	void getSiteLimits(int& siteNum, std::vector<int>& bandwidthLimit);
	// siteNum 填边缘结点数量 clientNum 填客户节点数量 graph 填边表
	void getQosGraph(int& baseCost, std::vector<std::pair<int, int>>& graph);


	/*Output Manager Method*/
	void outputInit();
	void clearOutputInfor();
	void setTime(int timeID);
	void setClient(int clientID);
	void setSite(int siteID);
	void writeLog(int streamID);
	void writeLog(int timeID, int clientID, int siteID, int streamID);
	void writeFile(std::string filePath);



	void debugDataManager();
};


